/**
 * -----------------------------------
 *  Copyright (c) 2021-2023
 *  All rights reserved, Designed By www.linfeng.tech
 *  林风社交论坛商业版本请务必保留此注释头信息
 *  商业版授权联系技术客服	 QQ:  3582996245
 *  严禁分享、盗用、转卖源码或非法牟利！
 *  版权所有 ，侵权必究！
 * -----------------------------------
 */
package io.linfeng.modules.admin.controller;

import java.util.Arrays;
import java.util.Map;

import io.linfeng.common.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import io.linfeng.modules.admin.entity.MessageEntity;
import io.linfeng.modules.admin.service.MessageService;
import io.linfeng.common.utils.PageUtils;
import io.linfeng.common.utils.R;



/**
 * 
 *  消息管理
 * @author linfeng
 * @email 2445465217@qq.com
 * @date 2022-01-26 13:15:30
 */
@RestController
@RequestMapping("admin/message")
@Api(tags = "管理端——消息管理")
public class MessageController {

    @Autowired
    @Lazy
    private MessageService messageService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:message:list")
    @ApiOperation("消息列表分页")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = messageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{mId}")
    @RequiresPermissions("admin:message:info")
    @ApiOperation("消息详情")
    public R info(@PathVariable("mId") Integer mId){
		MessageEntity message = messageService.getById(mId);

        return R.ok().put("message", message);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("admin:message:save")
    @ApiOperation("消息保存")
    public R save(@RequestBody MessageEntity message){
		messageService.save(message);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("admin:message:update")
    @ApiOperation("消息修改")
    public R update(@RequestBody MessageEntity message){
		messageService.updateById(message);

        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除消息")
    @PostMapping("/delete")
    @RequiresPermissions("admin:message:delete")
    @ApiOperation("消息删除")
    public R delete(@RequestBody Integer[] mIds){
		messageService.removeByIds(Arrays.asList(mIds));

        return R.ok();
    }

}
